import { FC, useContext, useEffect, useRef, useState } from "react";
import styles from "./index.module.less";
import { message } from "antd";
import { BigScreenContext } from "@/pages/Dashboard/context/BigScreenContext";

const Header: FC = () => {
  const context = useContext(BigScreenContext);
  // const jumpFunc = useJumpFun();
  const [timeInfo, setTimeInfo] = useState({
    time: "",
    date: "",
    week: "",
  });

  const settimeoutTime = useRef<number>(60);

  const getDate = () => {
    const date = new Date();
    const week = [
      "星期日",
      "星期一",
      "星期二",
      "星期三",
      "星期四",
      "星期五",
      "星期六",
    ];
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    // const minute = date.getMinutes();
    const minute = date.getUTCMinutes();
    const secound = date.getSeconds();
    const showMinute = minute < 10 ? "0" + minute : minute;

    setTimeInfo({
      time: `${hour}:${showMinute}`,
      date: `${year}年${month}月${day}日`,
      week: week[date.getDay()],
    });
    settimeoutTime.current = 60 - secound;

    setTimeout(() => {
      getDate();
    }, settimeoutTime.current * 1000);
  };

  const jumpClick = () => {
    console.log("context", context);
    const { currentKey } = context;
    // if (currentKey === 'stabilityAssessment') {
    //   jumpFunc('/autofactory/PerformanceEvaluation', true);
    //   return;
    // }
    // if (currentKey === 'dynamicRisk') {
    //   jumpFunc('/autofactory/DynamicRiskEvaluation', true, false);
    //   return;
    // }
    // if (currentKey === 'valve') {
    //   jumpFunc(
    //     '/autofactory/GeneralWorkEvaluation?groupKey=稳定性评估',
    //     true,
    //     false,
    //   );
    //   return;
    // }
    // if (currentKey === 'technologyAnomaly') {
    //   jumpFunc(
    //     '/autofactory/GeneralWorkEvaluation?groupKey=工艺异常预警',
    //     true,
    //     false,
    //   );
    //   return;
    // }
    // if (currentKey === 'controlPerformance') {
    //   jumpFunc(
    //     '/autofactory/GeneralWorkEvaluation?groupKey=控制性能评估',
    //     true,
    //     false,
    //   );
    //   return;
    // }
    // if (currentKey === 'equipmentReliability') {
    //   jumpFunc(
    //     '/autofactory/GeneralWorkEvaluation?groupKey=执行可靠性评估',
    //     true,
    //     false,
    //   );
    //   return;
    // }
    // if (currentKey === 'assetReliability') {
    //   jumpFunc('/autofactory/AssetsEvaluation', true, false);
    //   return;
    // }
    // if (currentKey === 'dataCredibility') {
    //   jumpFunc('/autofactory/CredibleEvaluation/CredibleTask', true, false);
    //   return;
    // }
    // if (currentKey === 'main') {
    //   jumpFunc('/autofactory/sysHomeManage', true, false);
    //   return;
    // }
    message.error("当前模块暂未开发或者暂未配置跳转页面");
  };

  useEffect(() => {
    getDate();
  }, []);

  return (
    <>
      <div className={styles["header"]}>
        {/* <div className={styles["header-title"]}>XXX系统</div> */}
        <div className={styles["header-title"]}>
          <div className={styles["font"]}></div>
        </div>
        <div className={styles["header-time-area"]}>
          <div className={styles["time"]}>{timeInfo.time}</div>
          <div className={styles["date-info"]}>
            <span className={styles["week"]}>{timeInfo.week}</span>
            <br />
            <span className={styles["date"]}>{timeInfo.date}</span>
          </div>
          {/* <span
            style={{ fontSize: 14, marginLeft: 8, cursor: "pointer" }}
            onClick={jumpClick}
          >
            设置
          </span> */}
        </div>
      </div>
    </>
  );
};

export default Header;
